package com.ybfenpan.controller.admin.wealth;


import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.service.WageDetailService;
import com.ybfenpan.taglib.pagetag.Pagination;
import com.ybfenpan.utils.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * Created by Administrator on 2016/3/25.
 */
@Controller

public class WageDetailListController extends BaseController {
    @Resource
    private WageDetailService wageDetailService;


    @RequestMapping("admin/wealth/wageDetailList.shtml")
    public String list(HttpServletRequest request) throws Exception {
        HashMap formMap = getParameterMap(request);
        String startDate = MapUtil.getString(formMap, "startDate");
        String endDate = MapUtil.getString(formMap, "endDate");

        if (startDate != null && !startDate.equals("") && endDate != null && !endDate.equals("")) {
            //+1天

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟

            Date newEndDate = sdf.parse(endDate);

            long temp = newEndDate.getTime() + 24 * 60 * 60 * 1000;
            newEndDate = new Date(temp);

            String newEndDateString = sdf.format(newEndDate);
            formMap.put("where", " commitDate>= '" + startDate + "' and commitDate<= '" + newEndDateString + "'");    //  时间查询
        }

        formMap.put("pagination.orderBy", " id desc");  //排列
        Pagination page = wageDetailService.queryForPageList(formMap);


        //工资
        Map<String, Object> mapWageNumAll = new HashMap<String, Object>();
        mapWageNumAll.put("diyUpdate", "sum(wageNum)");

        double wageNumAll = 0d;
        if (wageDetailService.queryForObject("sumSql", mapWageNumAll) != null) {
            wageNumAll = wageDetailService.queryForObject("sumSql", mapWageNumAll);
        }

        //奖金1
        Map<String, Object> mapWage1All = new HashMap<String, Object>();
        mapWage1All.put("diyUpdate", "sum(wage1)");
        double wage1All = 0d;

        if (wageDetailService.queryForObject("sumSql", mapWage1All) != null) {
            wage1All = wageDetailService.queryForObject("sumSql", mapWage1All);
        }

        //奖金2
        Map<String, Object> mapWage2All = new HashMap<String, Object>();
        mapWage2All.put("diyUpdate", "sum(wage2)");
        double wage2All = 0d;

        if (wageDetailService.queryForObject("sumSql", mapWage2All) != null) {
            wage2All = wageDetailService.queryForObject("sumSql", mapWage2All);
        }

        //奖金3
        Map<String, Object> mapWage3All = new HashMap<String, Object>();
        mapWage3All.put("diyUpdate", "sum(wage3)");
        double wage3All = 0d;

        if (wageDetailService.queryForObject("sumSql", mapWage3All) != null) {
            wage3All = wageDetailService.queryForObject("sumSql", mapWage3All);
        }

        //奖金4
        Map<String, Object> mapWage4All = new HashMap<String, Object>();
        mapWage4All.put("diyUpdate", "sum(wage4)");
        double wage4All = 0d;

        if (wageDetailService.queryForObject("sumSql", mapWage4All) != null) {
            wage4All = wageDetailService.queryForObject("sumSql", mapWage4All);
        }

        //奖金5
        Map<String, Object> mapWage5All = new HashMap<String, Object>();
        mapWage5All.put("diyUpdate", "sum(wage5)");
        double wage5All = 0d;
        if (wageDetailService.queryForObject("sumSql", mapWage5All) != null) {
            wage5All = wageDetailService.queryForObject("sumSql", mapWage5All);
        }

        //奖金6
        Map<String, Object> mapWage6All = new HashMap<String, Object>();
        mapWage6All.put("diyUpdate", "sum(wage6)");
        double wage6All = 0d;

        if (wageDetailService.queryForObject("sumSql", mapWage6All) != null) {
            wage6All = wageDetailService.queryForObject("sumSql", mapWage6All);
        }

        //奖金7
        Map<String, Object> mapWage7All = new HashMap<String, Object>();
        mapWage7All.put("diyUpdate", "sum(wage7)");
        double wage7All = 0d;

        if (wageDetailService.queryForObject("sumSql", mapWage7All) != null) {
            wage7All = wageDetailService.queryForObject("sumSql", mapWage7All);
        }

        //奖金8
        Map<String, Object> mapWage8All = new HashMap<String, Object>();
        mapWage8All.put("diyUpdate", "sum(wage8)");
        double wage8All = 0d;
        if (wageDetailService.queryForObject("sumSql", mapWage8All) != null) {
            wage8All = wageDetailService.queryForObject("sumSql", mapWage8All);
        }

        //报单人数
        Map<String, Object> mapActiveNumAll = new HashMap<String, Object>();
        mapActiveNumAll.put("diyUpdate", "sum(activeNum)");
        double activeNumAll = 0d;

        if (wageDetailService.queryForObject("sumSql", mapActiveNumAll) != null) {
            activeNumAll = wageDetailService.queryForObject("sumSql", mapActiveNumAll);
        }

        //注册人数
        Map<String, Object> mapRegistNumAll = new HashMap<String, Object>();
        mapRegistNumAll.put("diyUpdate", "sum(registNum)");
        double registNumAll = 0d;

        if (wageDetailService.queryForObject("sumSql", mapRegistNumAll) != null) {
            registNumAll = wageDetailService.queryForObject("sumSql", mapRegistNumAll);
        }

        //报单业绩
        Map<String, Object> mapActiveYeAll = new HashMap<String, Object>();
        mapActiveYeAll.put("diyUpdate", "sum(activeYe)");
        double activeYeAll = 0d;

        if (wageDetailService.queryForObject("sumSql", mapActiveYeAll) != null) {
            activeYeAll = wageDetailService.queryForObject("sumSql", mapActiveYeAll);
        }

        //打款总数
        Map<String, Object> mapDaNumAll = new HashMap<String, Object>();
        mapDaNumAll.put("diyUpdate", "sum(daNum)");
        double daNumAll = 0d;

        if (wageDetailService.queryForObject("sumSql", mapDaNumAll) != null) {
            daNumAll = wageDetailService.queryForObject("sumSql", mapDaNumAll);
        }

        //收款总数
        Map<String, Object> mapShouNumAll = new HashMap<String, Object>();
        mapShouNumAll.put("diyUpdate", "sum(shouNum)");
        double shouNumAll = 0d;

        if (wageDetailService.queryForObject("sumSql", mapShouNumAll) != null) {
            shouNumAll = wageDetailService.queryForObject("sumSql", mapShouNumAll);
        }


        request.setAttribute("wageNumAll", wageNumAll);
        request.setAttribute("wage1All", wage1All);
        request.setAttribute("wage2All", wage2All);
        request.setAttribute("wage3All", wage3All);
        request.setAttribute("wage4All", wage4All);
        request.setAttribute("wage5All", wage5All);
        request.setAttribute("wage6All", wage6All);
        request.setAttribute("wage7All", wage7All);
        request.setAttribute("wage8All", wage8All);
        request.setAttribute("activeNumAll", activeNumAll);
        request.setAttribute("activeYeAll", activeYeAll);
        request.setAttribute("registNumAll", registNumAll);
        request.setAttribute("daNumAll", daNumAll);
        request.setAttribute("shouNumAll", shouNumAll);
        request.setAttribute(Pagination.pageBeanName, page);

        return "admin/wealth/wageDetailList";
    }


}
